<template>
	<view>
		<!-- 常用功能模块 -->
		<view style="margin-bottom:250rpx;"><Common></Common></view>
		<!-- 数据展示 -->
		<Shuju></Shuju>
		<!-- 拓展功能模块 -->
		<Expand></Expand>
	</view>
</template>

<script lang="ts" setup>
	import {ref,reactive} from "vue"
	import Common from "./components/common.vue"
	import {onLoad,onShow} from "@dcloudio/uni-app"
	import Shuju from "./components/shuju.vue"
	import Expand from "./components/expand.vue"
	import http from "@/utils/request.js"
	import websocketUtil from "@/utils/websocketUtil.js"
	onLoad((e)=>{
		let response = http.get('/message/getnoreadnum',{
			receive_id:uni.getStorageSync('userinfo').user_id,
			is_user_send:0
		})
		response.then(res=>{
			if(res.data.code===200){
				getApp().globalData.noreadnum=res.data.data
				if(getApp().globalData.noreadnum>0)uni.setTabBarBadge({
				index:1,
				text:String(getApp().globalData.noreadnum)
			})
			}
		})
		let websocket = new websocketUtil("ws://localhost:8082",5000)
		getApp().globalData.socket=websocket
		getApp().globalData.socket.send(JSON.stringify({sendid:'u'+uni.getStorageSync('userinfo').user_id,receiveid:'u'+uni.getStorageSync('userinfo').user_id}))
		getApp().globalData.socket.getMessage(()=>{
			getApp().globalData.noreadnum++;
			let hh=getCurrentPages()
			if(hh.length>1)getApp().globalData.istabbar=false
			if(getApp().globalData.istabbar)uni.setTabBarBadge({
				index:1,
				text:String(getApp().globalData.noreadnum)
			})
		})
	})
	onShow(()=>{
		if(!getApp().globalData.istabbar){
			getApp().globalData.istabbar=true
			uni.setTabBarBadge({
				index:1,
				text:String(getApp().globalData.noreadnum)
			})
		}
	})
	
</script>

<style lang="scss">

</style>
